package com.yb0os1.config;

import com.yb0os1.result.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController("adminShopController")
@RequestMapping("/admin/shop")
@Tag(name = "店铺相关接口")
@Slf4j
public class ShopController {
    @Autowired
    private RedisTemplate redisTemplate;
    private final String SHOP_STATUS = "SHOP_STATUS";
    @Operation(summary = "设置店铺营业状态")
    @PutMapping("/{status}")
    public Result<String> setStatus(@PathVariable Integer status){
        log.info("设置店铺的营业状态{}",status==1?"营业中":"打样中");
        redisTemplate.opsForValue().set(SHOP_STATUS,status);
        return Result.success();
    }

    @Operation(summary = "查询店铺营业状态")
    @GetMapping("/status")
    public Result<Integer> getStatus(){
        return Result.success((Integer) redisTemplate.opsForValue().get(SHOP_STATUS));
    }
}
